java客户端中的elasticsearch geohash方面
我在elasticsearch中找到了this amazing plugin用于创建基于geohash的方面。 它在头部加成中似乎工作得很好。我只是不太确定如何从JavaClient代码运行这个
我编写了运行匹配查询的代码,但不确定如何向其中添加geohash过滤器
{
"query": {
"match_all": {}
},
"facets": {
"places": {
"geohash": {
"field": "location",
"factor": 0.9
}
}
}
}
我原以为下面的话会有帮助,但毫无帮助。它抛出
Exception in thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed; shardFailures {[IokTP1RuQ520T86dxU345w][easythahr][1]: SearchParseException[[easythahr][1]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][1]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][2]: SearchParseException[[easythahr][2]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][2]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][3]: SearchParseException[[easythahr][3]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][3]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][4]: SearchParseException[[easythahr][4]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][4]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }{[IokTP1RuQ520T86dxU345w][easythahr][0]: SearchParseException[[easythahr][0]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"facets_binary":"InBsYWNlcyJ7ImZhY2V0cyI6eyJnZW9IYXNoIjp7ImZpZWxkIjoibG9jYXRpb24iLCJmYWN0b3IiOjAuOX19fQ=="}]]]; nested: SearchParseException[[easythahr][0]: from[0],size[100]: Parse Failure [No facet type found for [facets]]]; }
XContentBuilder b = jsonBuilder().startObject("places")
.startObject("geoHash")
.field("field", "location")
.field("factor",0.9)
.endObject()
.endObject();
SearchResponse response = client.prepareSearch("easythahr")
.setTypes("com.easytha.Student")
.setQuery(matchQuery)
.setFacets(b)
.setFrom(0)
.setSize(100)
.execute()
.actionGet();
# 1 楼答案
我正在使用this plugin,这也在您提供的链接中提到。这是一种构建其方面的方法,它可以完美地工作
第二种方式: 将jar文件添加到buildpath后,可以使用以下命令